<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<style>
.btn_un
{
	cursor:pointer;
	color:white;
	width:68px;
	height:24px;
	border:0px;
	background-image: url(${pageContext.request.contextPath}/images/speedreport/btn_save_un.png);
}

.btn_nu
{
	cursor:pointer;
	color:white;
	width:68px;
	height:24px;
	border:0px;
	background-image: url(${pageContext.request.contextPath}/images/speedreport/btn_save_nu.png);
}

.spread_un
{
	vertical-align: bottom;
	background-image: url("");
	width: 61px; 
	height: 22px
}

.spread_nu
{
	vertical-align: bottom;
	background-image: url("${pageContext.request.contextPath}/images/speedreport/mousemove_bg.png");
	width: 61px; 
	height: 22px;
	color: white;
}

</style>
<script type="text/javascript">
	var dyColumns=null;
	var seqNextVal=null;
	var dimNames=null;
	//页面加载完成事件-begin
	$(function() 
	{
		$(".listtable").zebra(); 
		//指标名称绑定change事件
		//$('#dqm_accuracyruleconf_rulenameinputadd').bind('change',checkRuleName);
		
		//获得主键id来赋值给ruleId
		$.ajax({
			url:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!getRuleId.action',
			dataType:'json',
			success:function(result){
				seqNextVal=result;
			}
		});
		//规则算法
		$('#dqm_accuracyruleconf_rulealgorithmselectadd').combobox({
			url:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!getDic.action?codeType=ruleAlgorithm',  
			valueField:'codeValue',
			textField:'codeName',
			required: true,
			editable:false,
			onLoadSuccess:function(){
				//不让第一条为默认选择项
				$('#dqm_accuracyruleconf_rulealgorithmselectadd').combobox('unselect',0);
			}
		});
		//指标名称
		$('#dqm_accuracyruleconf_kqiidselectadd').combogrid({
			url: '${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!getAllKqiName.action',
			panelWidth: 550,
			panelHeight:300,
			mode: 'remote',
			idField: 'kqiid',
			pagination:true,
			pageList: [10,20,30],
			textField: 'kqiname',
			required: true,
			fit:true,
			border:false,
			editable:false,
			sortName:'createtime',
			sortOrder:'desc',
			columns: [[ {field:'kqiid',title:'指标编码',width:55},
						{field:'kqiname',title:'指标名称',width:75,formatter:function(value,rowData,rowIndex){
							return '<span title="'+value+'">'+value+'<span>';
						}},
						{field:'datalevel',title:'数据提取层',width:55},
						{field:'kqisql',title:'指标sql',width:395,resizable:true,formatter:function(value,rowData,rowIndex){
							return '<span title="'+value+'">'+value+'<span>';
						}},
					]],
			onSelect:function(rowIndex, rowData){
				//给"指标sql"这个文本域赋值
				document.getElementById("dqm_accuracyruleconf_kqisqltextareaadd").innerText=rowData.kqisql;
				//ajax请求获取动态要加载的列信息
				$.ajax({
					url:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!getDgColumns4Add.action?kqiId='+rowData.kqiid,
					dataType:'json',
					success:function(result){
						if(result.length==0)
						{
							$('#dqm_accuracyruleconf_dimconfbtndivadd').css("display", "none");
						}else if(result.length>0)
						{
							$('#dqm_accuracyruleconf_dimconfbtndivadd').css("display", "block");
							dyColumns=result;
						}
					}
				});
				
				//ajax请求获取该指标sql的维度名称
				$.ajax({
					url:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!getDimProperties.action?kqiId='+rowData.kqiid,
					dataType:'json',
					success:function(result){
						dimNames=result;
					}
				});
			},
			toolbar:'#dqm_accuracyruleconf_kqiidselecttoolbaradd',
			onLoadSuccess:function(){
				var sqlDiv=$("td[field='kqisql'] div");//如果kqisql的内容太长，则由...代替
				sqlDiv.css({
					"white-space":"nowrap",
					"text-overflow":"ellipsis",
					"-o-text-overflow":"ellipsis",
					"overflow":"hidden"
				});
				var kqiNameDiv=$("td[field='kqiname'] div");//如果kqiName的内容太长，则由...代替
				kqiNameDiv.css({
					"white-space":"nowrap",
					"text-overflow":"ellipsis",
					"-o-text-overflow":"ellipsis",
					"overflow":"hidden"
				});
			}
		});
		
		//模板
		$('#dqm_accuracyruleconf_templateIdselectadd').combogrid({
			url: '${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!getAllTemplate.action',
			panelWidth: 550,
			panelHeight:300,
			idField: 'templateId',
			textField: 'templateName',
			pagination:true,
			pageList: [10,20,30],
			required: true,
			fit:true,
			border:false,
			editable:false,
			columns: [[
						{field:'templateName',title:'模板名称',width:110,formatter:function(value,rowData,rowIndex){
							return '<span title="'+value+'">'+value+'<span>';
						}},
						{field:'templateContent',title:'报告内容',width:415,editor:'text',formatter:function(value,rowData,rowIndex){
							return '<span title="'+value+'">'+value+'<span>';
						}},
					]],
			onSelect:function(rowIndex, rowData){
				//给报告内容文本域赋值
				document.getElementById("dqm_accuracyruleconf_reportcontenttextareaadd").innerText=rowData.templateContent;
			},
			toolbar:'#dqm_accuracyruleconf_templateIdselecttoolbaradd',
			onLoadSuccess:function(){
				var templateNameDiv=$("td[field='templateName'] div");//如果kqisql的内容太长，则由...代替
				templateNameDiv.css({
					"white-space":"nowrap",
					"text-overflow":"ellipsis",
					"-o-text-overflow":"ellipsis",
					"overflow":"hidden"
				});
				var templateContentDiv=$("td[field='templateContent'] div");//如果kqiName的内容太长，则由...代替
				templateContentDiv.css({
					"white-space":"nowrap",
					"text-overflow":"ellipsis",
					"-o-text-overflow":"ellipsis",
					"overflow":"hidden"
				});
			}
		});
		
		//告警级别
		$('#dqm_accuracyruleconf_warnlevelselectadd').combobox({  
			url:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!getDic.action?codeType=warnLevel',  
			valueField:'codeValue',
			textField:'codeName',
			required: true,
			editable:false,
			onLoadSuccess:function(){
				//不让第一条为默认选择项
				$('#dqm_accuracyruleconf_warnlevelselectadd').combobox('unselect',0);
			}
		});
		//阀值上限运算符
		$('#dqm_accuracyruleconf_thresholdmaxoperatorselectadd').combobox({  
			url:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!getDic.action?codeType=thresholdOperator&thresholdName=max',  
			valueField:'codeValue',
			textField:'codeName',
			required: true,
			editable:false,
			//处理<符号在IE8中不能正常显示的问题
			formatter: function(row){
				var opts = $(this).combobox('options');
				if('<'==row[opts.textField])
				{
					return '&lt;';
				}
				return row[opts.textField];
			},
			onLoadSuccess:function(){
				//不让第一条为默认选择项
				$('#dqm_accuracyruleconf_thresholdmaxoperatorselectadd').combobox('unselect',0);
			}
		});
		//阀值下限运算符
		$('#dqm_accuracyruleconf_thresholdminoperatorselectadd').combobox({  
			url:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!getDic.action?codeType=thresholdOperator&thresholdName=min',  
			valueField:'codeValue',
			textField:'codeName',
			required: true,
			editable:false,
			onLoadSuccess:function(){
				//不让第一条为默认选择项
				$('#dqm_accuracyruleconf_thresholdminoperatorselectadd').combobox('unselect',0);
			}
		});
		//combogrid中的下拉列表
		//=============================================================================================
		//指标周期类型
		$.ajax({
			url:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!getDic.action?codeType=periodType&method=list',
			dataType:'json',
			success:function(result){
				var periodtypeSelect=document.getElementById("dqm_accuracyruleconf_periodtypecombogridselectadd");
				for(var i=0;i<result.length;i++)
				{
					var opt=new Option();
					opt.value=result[i].codeValue;
					opt.text=result[i].codeName;
					periodtypeSelect.add(opt);
				}
			}
		});
		
		
		//数据提取层
		$.ajax({
			url:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!getDic.action?codeType=dataLevel&method=list',
			dataType:'json',
			success:function(result){
				var dataLevelSelect=document.getElementById("dqm_accuracyruleconf_dataLevelcombogridselectadd");
				for(var i=0;i<result.length;i++)
				{
					var opt=new Option();
					opt.value=result[i].codeValue;
					opt.text=result[i].codeName;
					dataLevelSelect.add(opt);
				}
			}
		});
		
	});//页面加载完成事件-end
	
	//判断规则名称是否已经存在
	function checkRuleName()
	{
		var ruleName=$('#dqm_accuracyruleconf_rulenameinputadd').val();
		$.ajax({
			url:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!checkRuleName.action',
			data:{ruleName:ruleName},
			dataType:'json',
			success:function(data){
				if(data=='1'){
					$.messager.alert('提示','规则名称['+ruleName+']已经存在！');
					$('#dqm_accuracyruleconf_rulenameinputadd').val('').focus();
				}
			}
		});
	}
	
	//st:对象  type:class名称  change:改变小图标的名称
	function cbart (st,type,change) 
	{
		document.getElementById(st).className = type;
		if(change!=""&&change!=null&&change!=undefined)
		{
			$("#"+st).children().children().attr("src","${pageContext.request.contextPath}/images/speedreport/"+change);
		}
	} 
	function sbart (st,type,change)
	{
		document.getElementById(st).className = type;
		if(change!=""&&change!=null&&change!=undefined)
		{
			$("#"+st).children().children().attr("src","${pageContext.request.contextPath}/images/speedreport/"+change);
		}
	}
	//查询Kqi信息
	function queryKqi()
	{
		var kqiNameForComboGrid=$('#dqm_accuracyruleconf_kqinamecombogridinputadd').val();
		var periodType=$('#dqm_accuracyruleconf_periodtypecombogridselectadd').val();
		if(periodType=='undefined')
		{
			periodType=null;
		}
		var dataLevel=$('#dqm_accuracyruleconf_dataLevelcombogridselectadd').val();
		if(dataLevel=='undefined')
		{
			dataLevel=null;
		}
		var query={kqiNameForComboGrid:kqiNameForComboGrid,periodType:periodType,dataLevel:dataLevel};
		var grid=$('#dqm_accuracyruleconf_kqiidselectadd').combogrid('grid');
		$(grid).datagrid('options').queryParams=query;
		$(grid).datagrid('load');
	}
	//重置kqi查询条件
	function doResetQueryKqi()
	{
		$('#dqm_accuracyruleconf_kqinamecombogridinputadd').val('');
		var periodtypeOptions=document.getElementById("dqm_accuracyruleconf_periodtypecombogridselectadd").options;
		var periodtypeLength=periodtypeOptions.length;
		for(var i=0;i<periodtypeLength;i++)
		{
			if(periodtypeOptions[i].text=='全部')
			{
				periodtypeOptions[i].selected=true;
			}
		}
		
		var dataLevelOptions=document.getElementById("dqm_accuracyruleconf_dataLevelcombogridselectadd").options;
		var dataLevelLength=dataLevelOptions.length;
		for(var i=0;i<dataLevelLength;i++)
		{
			if(dataLevelOptions[i].text=='全部')
			{
				dataLevelOptions[i].selected=true;
			}
		}
	}
	//查询模板信息
	function queryTemplate()
	{
		var templateName=$('#dqm_accuracyruleconf_templatenamecombogridinputadd').val();	
		var query={templateName:templateName};
		var grid=$('#dqm_accuracyruleconf_templateIdselectadd').combogrid('grid');
		$(grid).datagrid('options').queryParams=query;
		$(grid).datagrid('load');
	}
	//重置查询模板条件
	function doResetQueryTemplate()
	{
		$('#dqm_accuracyruleconf_templatenamecombogridinputadd').val('');
	}
	//不配置维度，直接保存规则
	function saveRule()
	{
		var d = $('#dqm_accuracyruleconf_adddialog');
		//form表单提交 
		$('#dqm_accuracyruleconf_addbaseform').form('submit', {
			url : '${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!createAccuracyRuleConf.action?ruleId='+seqNextVal,
			success : function(result) {
				try {
					var r = $.parseJSON(result);
					$.messager.show({
						title : '提示',
						msg : r.returnMsg
					});
					d.dialog('close');
					if (r.returnFlag) {
						//重新加载datagrid
						$('#dqm_accuracyruleconf_rulelisttab').datagrid('reload');
					}
				} catch (e) {
					$.messager.alert('提示', result);
					d.dialog('close');
				}
			}
		});
	}
	
	//保存维度信息
	function saveDim()
	{
		if($('#dqm_accuracyruleconf_dimdatagridadd').datagrid('getChanges').length)
		{
			//获取datagrid的配置信息
			var allColumns=$('#dqm_accuracyruleconf_dimdatagridadd').datagrid('options').columns[0];
			var columns = new Array();
			for(var i=0;i<allColumns.length;i++)
			{
				if(!("dimId"==allColumns[i]['field']||"thresholdMax"==allColumns[i]['field']||"thresholdMin"==allColumns[i]['field']||"thresholdMaxOperator"==allColumns[i]['field']||"thresholdMinOperator"==allColumns[i]['field']))
				{
					columns.push(allColumns[i]);
				}
			}
			var inserted=$('#dqm_accuracyruleconf_dimdatagridadd').datagrid('getChanges',"inserted");
			var deleted=$('#dqm_accuracyruleconf_dimdatagridadd').datagrid('getChanges',"deleted");
			var updated=$('#dqm_accuracyruleconf_dimdatagridadd').datagrid('getChanges',"updated");
			var effectRow = new Object();
			if(inserted.length){
				effectRow["inserted"] = JSON.stringify(inserted);
			}
			if(deleted.length){
				effectRow["deleted"] = JSON.stringify(deleted); 
			}
			if(updated.length){
				effectRow["updated"] = JSON.stringify(updated);
			}
			effectRow["ruleId"]=JSON.stringify(seqNextVal);
			effectRow["columns"]=JSON.stringify(columns);
			
			$.post(
					"${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!saveDimsRule.action",
					effectRow,
					function(rsp){
						if (rsp.returnFlag) {
							$.messager.alert("提示", rsp.returnMsg); 
							$('#dqm_accuracyruleconf_dimdatagridadd').datagrid('acceptChanges');
							reject();
						}
					},
					"json"
				);
		}
	}
	
	//点击维度配置按钮事件
	function dimConfig()
	{
		//form表单提交 
		$('#dqm_accuracyruleconf_addbaseform').form('submit', {
			url : '${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!createAccuracyRuleConf.action?ruleId='+seqNextVal,
			success : function(result) {
				try {
					var r = $.parseJSON(result);
					if (r.returnFlag) {
						$.messager.alert('提示','基本信息已经保存成功,可以继续按维度添加规则，也可以关闭离开');
						initSimpleBaseInfo();
						initDimConf();
					}
				} catch (e) {
					$.messager.alert('提示', '基本信息保存失败');
				}
			}
		});
	}
	//给简单的基本信息div中的控件赋值
	function initSimpleBaseInfo()
	{
		var ruleName=$('#dqm_accuracyruleconf_rulenameinputadd').val();
		var ruleAlgorithm=$('#dqm_accuracyruleconf_rulealgorithmselectadd').combobox('getText');
		var warnLevel=$('#dqm_accuracyruleconf_warnlevelselectadd').combobox('getText');
		
		$('#dqm_accuracyruleconf_rulenamelabeladd').html(ruleName);
		$('#dqm_accuracyruleconf_rulealgorithmlabeladd').html(ruleAlgorithm);
		$('#dqm_accuracyruleconf_warnlevellabeladd').html(warnLevel);
	}
	//给规则配置的div中的控件赋值
	function initDimConf()
	{
		//初始化datagrid
		$('#dqm_accuracyruleconf_dimdatagridadd').datagrid({
			url : '',
			title:'按维度添加规则',
			width:998,
			height:410,
			singleSelect:true,
			autoRowHeight:true,
			iconCls:'icon-edit',
			frozenColumns:[[  {field:'thresholdMax',title:'阀值上限',width:165,align:'center',
							editor:{
								type:'numberbox',
								options:
								{
									validType:'moreThen("dqm_accuracyruleconf_thresholdmininputadd")',
									min:-99999999999999.999999,
									max:99999999999999.999999,
									precision:6,
									required:true,
									missingMessage:'请填写数字(包括小数，负数)'
								}}
						},
						{field:'thresholdMin',title:'阀值下限',width:165,align:'center',
							editor:{
								type:'numberbox',
								options:
								{
									min:-99999999999999.999999,
									max:99999999999999.999999,
									precision:6,
									required:true,
									missingMessage:'请填写数字(包括小数，负数)'
								}}
						},
						{field:'thresholdMaxOperator',title:'上限运算符',width:165,align:'center',
							formatter:function(value,row){
								return row.thresholdMaxOperatorName;
							},
							editor:
							{
								type:'combobox',
								options:
								{
									valueField:'codeValue',
									textField:'codeName',
									url:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!getDic.action?codeType=thresholdOperator&thresholdName=max',
									required:true,
									editable:false,
									panelHeight:'auto',
									formatter: function(row){
										var opts = $(this).combobox('options');
										if('<'==row[opts.textField])
										{
											return '&lt;';
										}
										return row[opts.textField];
									}
								}
							}
						},
						{field:'thresholdMinOperator',title:'下限运算符',width:165,align:'center',
							formatter:function(value,row){
								return row.thresholdMinOperatorName;
							},
							editor:
							{
								type:'combobox',
								options:
								{
									valueField:'codeValue',
									textField:'codeName',
									url:'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!getDic.action?codeType=thresholdOperator&thresholdName=min',
									required:true,
									editable:false,
									panelHeight:'auto'
								}
							}
						}
					]],
			columns:[[]],
			toolbar:'#dqm_accuracyruleconf_dimdatagridaddtoolbar'
		});
		
		//获取datagrid的配置信息
		var dgOptions=$('#dqm_accuracyruleconf_dimdatagridadd').datagrid('options');
		//dyColumns类似:[{field:'dim_city',title:'南京'}，{field:'dim_city',title:'南京'}]
		for(var i=0;i<dyColumns.length;i++)
		{
			//往json对象中添加属性，变成类似:{field:'dim_city',title:'南京',width:80,align:'center',editor:'text'}
			dyColumns[i].editor="text";
			dyColumns[i].width=165;
			dyColumns[i].align="center";
			//向datagrid的第一个列列数组的最前面添加列
			dgOptions.columns[0].push(dyColumns[i]);
		}
		//重新配置datagrid
		$('#dqm_accuracyruleconf_dimdatagridadd').datagrid(dgOptions); 
		//重新加载datagrid
		$('#dqm_accuracyruleconf_dimdatagridadd').datagrid('reload');
		//隐藏基本信息填写页面，显示不能编辑的部分基本信息页面和维度配置页面
		$("#dqm_accuracyruleconf_baseinfodivadd").slideUp("slow");
		$("#dqm_accuracyruleconf_simplebaseinfodivadd").slideDown("slow");
		$("#dqm_accuracyruleconf_tipinfodivadd").slideDown("slow");
	}
	//展开按钮事件
	function spread()
	{
		$("#dqm_accuracyruleconf_beforesavebtndivadd").css("display", "none");//隐藏保存按钮
		$("#dqm_accuracyruleconf_dimconfbtndivadd").css("display", "none");//隐藏维度配置按钮
		$("#dqm_accuracyruleconf_aftersavebtndivadd").css("display", "block");//显示收缩按钮
		
		//显示基本信息填写页面，隐藏不能编辑的部分基本信息页面和维度配置页面
		$("#dqm_accuracyruleconf_baseinfodivadd").slideDown("slow");
		$("#dqm_accuracyruleconf_simplebaseinfodivadd").slideUp("slow");
		$("#dqm_accuracyruleconf_tipinfodivadd").slideUp("slow");
		
		//让input不可编辑
		$("#dqm_accuracyruleconf_baseinfodivadd").find("input").not("#dqm_accuracyruleconf_aftersavebtnadd").attr("disabled","disabled");
		//让combobox不可以编辑
		$("#dqm_accuracyruleconf_rulealgorithmselectadd").combobox("disable");
		$("#dqm_accuracyruleconf_thresholdminoperatorselectadd").combobox("disable");
		$("#dqm_accuracyruleconf_thresholdmaxoperatorselectadd").combobox("disable");
		$("#dqm_accuracyruleconf_warnlevelselectadd").combobox("disable");
		//让combogrid不可以编辑
		$("#dqm_accuracyruleconf_kqiidselectadd").combogrid("disable");
		$("#dqm_accuracyruleconf_templateIdselectadd").combogrid("disable");
		//让textarea不可编辑
		$("#dqm_accuracyruleconf_baseinfodivadd").find("textarea").attr("readonly","readonly");
	}
	//收缩按钮事件
	function shrink()
	{
		$("#dqm_accuracyruleconf_baseinfodivadd").slideUp("slow");
		$("#dqm_accuracyruleconf_simplebaseinfodivadd").slideDown("slow");
		$("#dqm_accuracyruleconf_tipinfodivadd").slideDown("slow");
	}
	//关闭弹出窗口
	function colseDialog()
	{
		$('#dqm_accuracyruleconf_adddialog').dialog('close');
	}
	//将指标sql中的维度列名称修改成中文名称
	function renameDim()
	{
		//向左收缩进去的时候，获取该propertygrid变换的行的内容
		if($("#dqm_accuracyruleconf_renamedimdivadd").css("display")=="block")
		{
			$('#dqm_accuracyruleconf_saverenameadd').hide();
			$('#dqm_accuracyruleconf_renameadd').show();
			jQuery("#dqm_accuracyruleconf_renamedimdivadd").animate({left: "0"},600,function(){
				$("#dqm_accuracyruleconf_renamedimdivadd").hide();
				});
			//修改propertygrid的列名称
			if($('#dqm_accuracyruleconf_dimprogridadd').propertygrid('getRows').length)
			{
				//获取propertygrid表格中的数据
				var rows=$('#dqm_accuracyruleconf_dimprogridadd').propertygrid('getRows');
				//获取datagrid的配置信息
				var dgOptions=$('#dqm_accuracyruleconf_dimdatagridadd').datagrid('options');
				var dgColumns=dgOptions.columns[0];
				for(var i=0;i<dgColumns.length;i++)
				{
					for(var j=0;j<rows.length;j++)
					{
						if(dgColumns[i]['field']==rows[j]['field'])
						{
							if((null!=rows[j]['value'])&&(rows[j]['value']!=''))
							{
								dgColumns[i]['title']=rows[j]['value'];
							}else
							{
								dgColumns[i]['title']=rows[j]['field'];
							}
						}
					}
				}
				dgOptions.columns[0]=dgColumns;
				//重新配置datagrid
				$('#dqm_accuracyruleconf_dimdatagridadd').datagrid(dgOptions); 
			}
		}
		//向右弹出来的时候，去获取维度列名称展示在propertygrid中
		else
		{
			$('#dqm_accuracyruleconf_renameadd').hide();
			$('#dqm_accuracyruleconf_saverenameadd').show();
			jQuery("#dqm_accuracyruleconf_renamedimdivadd").animate({left: "420px"},600);
			$("#dqm_accuracyruleconf_renamedimdivadd").show();
			//加载propertygrid中的数据
			$('#dqm_accuracyruleconf_dimprogridadd').propertygrid({
				width:300,
				height:150,
				showGroup:false,
				showHeader:true,
				scrollbarSize: 18,
				columns:[[
					{ field: 'name', title: '修改前维度列名', width: 150},
					{ field: 'value', title: '修改后维度列名', width: 150}
					]]
			});
			$('#dqm_accuracyruleconf_dimprogridadd').propertygrid('loadData',dimNames);
		}
	}
	
	//维度规则datagid的操作
	var editIndex = undefined;
	function endEditing(){
		if (editIndex == undefined){return true}
		if ($('#dqm_accuracyruleconf_dimdatagridadd').datagrid('validateRow', editIndex)){
			
			var thresholdMaxOperatorDd = $('#dqm_accuracyruleconf_dimdatagridadd').datagrid('getEditor', {index:editIndex,field:'thresholdMaxOperator'});
			var codeNameMax = $(thresholdMaxOperatorDd.target).combobox('getText');
			$('#dqm_accuracyruleconf_dimdatagridadd').datagrid('getRows')[editIndex]['thresholdMaxOperatorName'] = codeNameMax;
				
			var thresholdMinOperatorDd = $('#dqm_accuracyruleconf_dimdatagridadd').datagrid('getEditor', {index:editIndex,field:'thresholdMinOperator'});
			var codeNameMin = $(thresholdMinOperatorDd.target).combobox('getText');
			$('#dqm_accuracyruleconf_dimdatagridadd').datagrid('getRows')[editIndex]['thresholdMinOperatorName'] = codeNameMin;
			
			$('#dqm_accuracyruleconf_dimdatagridadd').datagrid('endEdit', editIndex);
			editIndex = undefined;
			return true;
		} else {
			return false;
		}
	}
	/*
	function onClickRow(index){
		if (editIndex != index){
			if (endEditing()){
				$('#dqm_accuracyruleconf_dimdatagridadd').datagrid('selectRow', index).datagrid('beginEdit', index);
				editIndex = index;
			} else {
				$('#dqm_accuracyruleconf_dimdatagridadd').datagrid('selectRow', editIndex);
			}
		}
	}*/
	function append(){
		if (endEditing()){
			$('#dqm_accuracyruleconf_dimdatagridadd').datagrid('appendRow',{});
			editIndex = $('#dqm_accuracyruleconf_dimdatagridadd').datagrid('getRows').length-1;
			$('#dqm_accuracyruleconf_dimdatagridadd').datagrid('selectRow', editIndex).datagrid('beginEdit', editIndex);
			//上下线值校验
			var editors = $('#dqm_accuracyruleconf_dimdatagridadd').datagrid('getEditors', editIndex);
			var maxEditor=editors[0];
			var minEditor=editors[1];
			maxEditor.target.bind('blur',function(){
				var maxValue=parseFloat(maxEditor.target.val());
				var minValue=parseFloat(minEditor.target.val());
				if(maxValue<minValue)
				{
					$.messager.alert('提示','上限值必须大于等于下限值');
				}
			});
			minEditor.target.bind('blur',function(){
				var maxValue=parseFloat(maxEditor.target.val());
				var minValue=parseFloat(minEditor.target.val());
				if(maxValue<minValue)
				{
					$.messager.alert('提示','下限值必须小于上线值');
				}
			});
		}
	}
	function remove(){
		if (editIndex == undefined){return}
		$('#dqm_accuracyruleconf_dimdatagridadd').datagrid('cancelEdit', editIndex).datagrid('deleteRow', editIndex);
		editIndex = undefined;
	}
	function accept(){
		if (endEditing()){
			$('#dqm_accuracyruleconf_dimdatagridadd').datagrid('acceptChanges');
		}
	}
	function reject(){
		$('#dqm_accuracyruleconf_dimdatagridadd').datagrid('rejectChanges');
		editIndex = undefined;
	}
	
	function commit()
	{
		if(endEditing())
		{
			saveDim();
		}
	}
	
</script>
<div class="" style="width:100%;height:100%">
	<form id="dqm_accuracyruleconf_addbaseform" method="post">
	<!--收缩之后上面要显示简单基本信息div-->
	<div id="dqm_accuracyruleconf_simplebaseinfodivadd" style="display:none;height:50%">
		<table border="0" cellpadding="0" cellspacing="0" style="width:100%;height:100%;background-image: url(${pageContext.request.contextPath}/images/speedreport/add_speedreport_bg.png)">
			<tr height="56px">
				<td style="padding-left:3px" width="120px">规则名称：<label id="dqm_accuracyruleconf_rulenamelabeladd"></td>
				<td width="120px">规则算法：<label id="dqm_accuracyruleconf_rulealgorithmlabeladd"></td>
				<td width="120px">告警级别：<label id="dqm_accuracyruleconf_warnlevellabeladd"></td>
				<td width="10px"><div id="dqm_accuracyruleconf_spreadbtndivadd" onclick="spread()" style="width:61px;height:22px;cursor:pointer;" onmouseout="cbart('dqm_accuracyruleconf_spreadbtndivadd','spread_un','spread_img_un.png')" onmouseover="sbart('dqm_accuracyruleconf_spreadbtndivadd','spread_nu','spread_img_nu.png')"><span style="vertical-align: bottom;">&nbsp;<img src="${pageContext.request.contextPath}/images/speedreport/spread_img_un.png">展开</span></div></td>
			</tr>
		 </table>
	</div>
		
	<!--基本信息div-->
	<div id="dqm_accuracyruleconf_baseinfodivadd" data-options="region:'north'" style="overflow-y:hidden;width:100%;height:100%;">
		<table border="0" cellpadding="0" cellspacing="0" style="width:100%;height:100%;" class="listtable">
		<tr>
			<td height="40px" style="text-align:right;width:15%"><span style="color:red;font-size:15px">*</span>规则名称：&nbsp;</td>
			<td height="40px" style="width:45%">
				<input id="dqm_accuracyruleconf_rulenameinputadd" type="text" name="ruleName"  class="easyui-validatebox"  data-options="invalidMessage:'规则名称已经存在或者包含特殊字符',delay:1000,required:true,missingMessage:'规则名称不能为空',validType:['length[0,85]','specialCharFilter(\'dqm_accuracyruleconf_rulenameinputadd\')','remote[\'${pageContext.request.contextPath}/basemgr/accuracyRuleConfAction!checkRuleName.action?operateType=add\',\'ruleName\']']"/>
			</td>
			<td height="40px" style="text-align:right;width:15%"><span style="color:red;font-size:15px">*</span>规则算法：&nbsp;</td>
			<td height="40px" style="width:25%">
				<input id="dqm_accuracyruleconf_rulealgorithmselectadd" type="text" name="ruleAlgorithm" panelHeight="auto"/>
			</td>
		</tr>
		
		<tr>
			<td height="40px" style="text-align:right;width:15%"><span style="color:red;font-size:15px">*</span>指标名称：&nbsp;</td>
			<td height="40px" style="width:45%">
				<input id="dqm_accuracyruleconf_kqiidselectadd" name="kqiId" type="text" panelHeight="auto"/>
			</td>
			<td height="40px" style="text-align:right;width:15%"><span style="color:red;font-size:15px">*</span>告警级别：&nbsp;</td>
			<td height="40px" style="width:25%">
				<input id="dqm_accuracyruleconf_warnlevelselectadd" type="text"  name="warnLevel" panelHeight="auto"/>
			</td>
		</tr>
		
		<tr>
			<td height="40px" style="text-align:right;width:15%"><span style="color:red;font-size:15px">*</span>阀值上限：&nbsp;</td>
			<td height="40px" style="width:45%">
				<input id="dqm_accuracyruleconf_thresholdmaxinputadd" type="text" name="thresholdMax"  class="easyui-numberbox" validType='moreThen("dqm_accuracyruleconf_thresholdmininputadd")' data-options="min:-99999999999999.999999,max:99999999999999.999999,precision:6,required:true,missingMessage:'请填写数字(包括小数，负数)'"/>
			</td>
			<td height="40px" style="text-align:right;width:15%"><span style="color:red;font-size:15px">*</span>阀值上限运算符：&nbsp;</td>
			<td height="40px" style="width:25%">
				<input id="dqm_accuracyruleconf_thresholdmaxoperatorselectadd" type="text" name="thresholdMaxOperator" panelHeight="auto"/>
			</td>
		</tr>
		
		<tr>
			<td height="40px" style="text-align:right;width:15%"><span style="color:red;font-size:15px">*</span>阀值下限：&nbsp;</td>
			<td height="40px" style="width:45%">
				<input id="dqm_accuracyruleconf_thresholdmininputadd" type="text" name="thresholdMin" class="easyui-numberbox" validType='lessThen("dqm_accuracyruleconf_thresholdmaxinputadd")' data-options="min:-9999999999999.999999,max:99999999999999.999999,precision:6,required:true,missingMessage:'请填写数字(包括小数，负数)'"/>
			</td>
			<td height="40px" style="text-align:right;width:15%"><span style="color:red;font-size:15px">*</span>阀值下限运算符：&nbsp;</td>
			<td height="40px" style="width:25%">
				<input id="dqm_accuracyruleconf_thresholdminoperatorselectadd" type="text" name="thresholdMinOperator" panelHeight="auto"/>
			</td>
		</tr>
		
		<tr>
			<td height="40px" style="text-align:right;width:15%"><span style="color:red;font-size:15px">*</span>模板名称：&nbsp;</td>
			<td height="40px" style="width:45%">
				<input id="dqm_accuracyruleconf_templateIdselectadd" name="templateId" type="text"/>
			</td>
			<td height="40px"></td>
			<td height="40px"></td>
		</tr>
		<tr>
			<td height="40px" style="text-align:right;width:15%">指标sql：&nbsp;</td>
			<td height="68px" colspan="3">
				<textarea id="dqm_accuracyruleconf_kqisqltextareaadd" readonly="readonly" style="width:90%;height:60px;"></textarea>
			</td>
		</tr>	
		<tr>
			<td height="40px" style="text-align:right;width:15%">模板内容：&nbsp;</td>
			<td height="68px" colspan="3">
				<textarea id="dqm_accuracyruleconf_reportcontenttextareaadd" readonly="readonly" style="width:90%;height:60px;"></textarea>
			</td>
		</tr>			
		<tr>
			<td height="40px" style="text-align:right;width:15%">口径描述：&nbsp;</td>
			<td height="68px" colspan="3">
				<textarea id="dqm_accuracyruleconf_caliberdesctextareaadd" name="caliberDesc" class="easyui-validatebox" style="width:90%;height:60px;"  data-options="validType:'length[0,166]'"></textarea>
			</td>
		</tr>
		
		<tr>
			<td height="40px" style="text-align:right;width:15%">说明：&nbsp;</td>
			<td height="68px" colspan="3">
				<textarea id="dqm_accuracyruleconf_remarktextareaadd" name="remark" class="easyui-validatebox" style="width:90%;height:60px;"  data-options="validType:'length[0,170]'"></textarea>
			</td>
		</tr>
		<tr>
			<td colspan="6" align="right" height="40px">
				<div id="dqm_accuracyruleconf_beforesavebtndivadd" style="float:right"><input id="dqm_accuracyruleconf_beforesavebtnadd" onclick="saveRule()" onmouseout="cbart('dqm_accuracyruleconf_beforesavebtnadd','btn_un')" onmouseover="sbart('dqm_accuracyruleconf_beforesavebtnadd','btn_nu')" height="24px" width="64px" type="button" value="保  存" class="btn_un">&nbsp;&nbsp;&nbsp;&nbsp;</div>
				<div id="dqm_accuracyruleconf_dimconfbtndivadd" style="display:none"><input id="dqm_accuracyruleconf_dimconfbtnadd" onclick="dimConfig()" onmouseout="cbart('dqm_accuracyruleconf_dimconfbtnadd','btn_un')" onmouseover="sbart('dqm_accuracyruleconf_dimconfbtnadd','btn_nu')" height="24px" width="64px" type="button" value="维度配置" class="btn_un">&nbsp;&nbsp;&nbsp;&nbsp;</div>
				<div id="dqm_accuracyruleconf_aftersavebtndivadd" style="display:none"><input id="dqm_accuracyruleconf_aftersavebtnadd" onclick="shrink()" onmouseout="cbart('dqm_accuracyruleconf_aftersavebtnadd','btn_un')" onmouseover="sbart('dqm_accuracyruleconf_aftersavebtnadd','btn_nu')" height="24px" width="64px" type="button" value="收  缩" class="btn_un">&nbsp;&nbsp;&nbsp;&nbsp;</div>
			</td>
		</tr>
		</table>
	</div>

	</form>
	
	<!--修改维度列名称的div-->
	<div id="dqm_accuracyruleconf_renamedimdivadd" style="z-index:998;top:250px;width:300px;border: 1px #98C5EB solid;position:fixed;_position:absolute;display: none;">
		<table id="dqm_accuracyruleconf_dimprogridadd">
		</table>
	</div>
	
	
	<!--维度规则配置信息div-->
	<div id="dqm_accuracyruleconf_tipinfodivadd" style="display:none;width:100%;height:50%">
		<table id="dqm_accuracyruleconf_dimdatagridadd">
		</table>
	
		<div id="dqm_accuracyruleconf_dimdatagridaddtoolbar" style="height:auto">
			<a id="dqm_accuracyruleconf_renameadd" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="renameDim()">自定义列名</a>
			<a id="dqm_accuracyruleconf_saverenameadd" href="javascript:void(0)" style="display: none" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="renameDim()">保存列名</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="append()">添加</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true" onclick="reject()">撤销 </a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true" onclick="commit()">提交</a>
		</div>
		
		<div id="dqm_accuracyruleconf_colsebtndivadd" align="right" style="padding-top:7px;padding-bottom:7px">
			<input id="dqm_accuracyruleconf_colsebtnadd" onclick="colseDialog()" onmouseout="cbart('dqm_accuracyruleconf_colsebtnadd','btn_un')" onmouseover="sbart('dqm_accuracyruleconf_colsebtnadd','btn_nu')" height="24px" width="64px" type="button" value="关  闭" class="btn_un"/>&nbsp;&nbsp;&nbsp;&nbsp;</div>
	</div>
	
	<!--指标名称combogrid的查询条件的toolbar-->
	<div id="dqm_accuracyruleconf_kqiidselecttoolbaradd" style="padding:5px;height:auto">
	<div id="dqm_accuracyruleconf_querykqidivadd" >
			<table border="0" cellpadding="0" cellspacing="0" height="100%"  width="100%" >
			<tr height="40px">
				<td style="text-align:right;width:10%;" nowrap="nowrap">
					<label>指标名称：</label>
				</td>
				<td style="text-align:left;width:15%;" nowrap="nowrap">
					<input id="dqm_accuracyruleconf_kqinamecombogridinputadd" name="kqiNameForComboGrid" type="text"/>
				</td>
				<td style="text-align:right;width:10%;" nowrap="nowrap">
					<label>周期类型：</label>
				</td>
				<td style="text-align:left;width:15%;padding-right:25px;" nowrap="nowrap">
					<select id="dqm_accuracyruleconf_periodtypecombogridselectadd" name="periodType" style="width:162px;height:22px;">
					</select>
				</td>
			</tr>
			<tr height="40px">
				<td style="text-align:right;width:10%;" nowrap="nowrap">
					<label>数据提取层：</label>
				</td>
				<td style="text-align:left;width:15%;padding-right:35px" nowrap="nowrap">
					<select id="dqm_accuracyruleconf_dataLevelcombogridselectadd" name="dataLevel" style="width:162px;height:22px;">
					</select>
				</td>
				<td style="width:10%;text-align:right;" nowrap="nowrap">
				</td>
				<td colspan="2" style="width:25%;text-align:right;" nowrap="nowrap">
					<input type="button" onclick="queryKqi()" value="查询" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/search.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑"/>	
					<input type="button" onclick="doResetQueryKqi()" value="重置" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/reset.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;margin-right:35px"/>						
				</td>
			</tr>
			</table>
	</div>
	</div>

	<!--模板名称combogrid的查询条件toolbar-->
	<div id="dqm_accuracyruleconf_templateIdselecttoolbaradd">
		<div id="dqm_accuracyruleconf_querytemplatedivadd">
				<table border="0" cellpadding="0" cellspacing="0" height="100%"  width="100%" >
					<tr height="40px">
						<td style="text-align:right;width:10%;" nowrap="nowrap">
							<label>模板名称：</label>
						</td>
						<td style="text-align:left;width:15%;" nowrap="nowrap">
							<input id="dqm_accuracyruleconf_templatenamecombogridinputadd" name="templateName" type="text"/>
						</td>
						<td style="width:10%;text-align:right;" nowrap="nowrap">
						</td>
						<td colspan="2" style="width:25%;text-align:right;" nowrap="nowrap">
							<input type="button"  onclick="queryTemplate()" value="查询" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/search.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑"/>	
							<input type="button"  onclick="doResetQueryTemplate()" value="重置" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/reset.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;margin-right:35px"/>						
						</td>
					</tr>
				</table>			
		</div>
	</div>
	
</div>